#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
void del(int* a, int n, int k)
{
	int b = 0;
	while (n>1)
	{
		b = (b + (k - 1)) % n;
		for (int i = b; i < n - 1; i++)
		{
			a[i] = a[i + 1];
		}
		n--;
	}
	printf("%d", a[0]);
}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int *a;
	a = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		a[i] = i + 1;
	}
	del(a, n, k);
	free(a);
	return 0;
}